﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Practices.Composite.Modularity;
using Microsoft.Practices.Composite.Regions;
using Microsoft.Practices.Unity;
using TelecoSystems.Modules.Contracts.Views;
using TelecoSystems.Infrastructure;
using TelecoSystems.Web.Services.Contracts;
using TelecoSystems.Web.Services.Customers;
using TelecoSystems.Web.Services.Products;
using TelecoSystems.Web.Services.Variants;

namespace TelecoSystems.Modules.Contracts
{
    public class ContractsModule : IModule
    {
        private readonly IRegionManager regionManager;
        private readonly IUnityContainer unityContainer;
        private const string MODULE_NAME = "Contracts"; 

        public ContractsModule(IRegionManager _regionManager, IUnityContainer _unityContainer)
        {
            regionManager = _regionManager;
            unityContainer = _unityContainer;
        }

        public void Initialize()
        {
            unityContainer.RegisterType<ContractsDomainContext>(new InjectionConstructor());
            unityContainer.RegisterType<CustomersDomainContext>(new InjectionConstructor());
            unityContainer.RegisterType<ProductsDomainContext>(new InjectionConstructor());
            unityContainer.RegisterType<VariantsDomainContext>(new InjectionConstructor());

            IRegion region = regionManager.Regions[RegionNames.MainRegion];
            ContractsModuleView cView = this.unityContainer.Resolve<ContractsModuleView>();
            region.Add(cView, cView.GetType().Name);
            region.Activate(cView);

            region = regionManager.Regions[MODULE_NAME + RegionNames.ModuleRegion];
            regionManager.RegisterViewWithRegion(MODULE_NAME + RegionNames.ModuleRegion, () => this.unityContainer.Resolve<ContractsBrowseView>());
        }
    }
}
